import Vue from 'vue'
import Router from 'vue-router'
import { component } from 'vuedraggable';
const Login = () => import(/* webpackChunkName: "login" */ '@/views/login/Login');
const Homepage = () => import(/* webpackChunkName: "homepage" */ '@/components/homepage/Homepage');
const Statistical = () => import(/* webpackChunkName: "statistical" */ '@/views/statistical/Statistical');
const Management = () => import(/* webpackChunkName: "management" */ '@/views/management/Management');
const Business = () => import(/* webpackChunkName: "business" */ '@/views/business/Business');
const Supplier = () => import(/* webpackChunkName: "supplier" */ '@/views/supplier/Supplier');
const Groupteam = () => import(/* webpackChunkName: "groupteam" */ '@/views/groupteam/Groupteam');
const Gongment = () => import(/* webpackChunkName: "gongment" */ '@/views/gongment/Gongment');
const Gongmoney = () => import(/* webpackChunkName: "gongmoney" */ '@/views/gongmoney/Gongmoney');
const Activity = () => import(/* webpackChunkName: "activity" */ '@/views/activity/Activity');
const Directly = () => import(/* webpackChunkName: "directly" */ '@/views/directly/Directly');
const Settlement = () => import(/* webpackChunkName: "settlement" */ '@/views/business/Settlement');
const Addmanagement = () => import(/* webpackChunkName: "addmanagement" */ '@/views/management/children/Addmanagement');
const Tuanorder = () => import(/* webpackChunkName: "tuanorder" */ '@/views/tuanorder/Tuanorder');
const Torderdetail = () => import(/* webpackChunkName: "torderdetail" */ '@/views/tuanorder/Torderdetail');
const Gongorder = () => import(/* webpackChunkName: "gongorder" */ '@/views/gongorder/Gongorder');
const Gongbao = () => import(/* webpackChunkName: "gongbao" */ '@/views/gongbao/Gongbao');
const Tuanbao = () => import(/* webpackChunkName: "tuanbao" */ '@/views/tuanbao/Tuanbao');
const Post = () => import(/* webpackChunkName: "post" */ '@/views/post/Post');
const Gongdepage = () => import(/* webpackChunkName: "gongdepage" */ '@/views/gongmoney/children/Gongdepage');
const Gorderdetail = () => import(/* webpackChunkName: "gorderdetail" */ '@/views/gongorder/children/Gorderdetail');
// const Addevent = () => import(/* webpackChunkName: "addevent" */ '@/views/directly/children/Addevent');
const Addeventpage = () => import(/* webpackChunkName: "addeventpage" */ '@/views/directly/children/Addeventpage');
const EditEventPage = () => import(/* webpackChunkName: "EditEventPage" */ '@/views/directly/children/EditEventPage');
const Groupteamdetail = () => import(/* webpackChunkName: "groupteamdetail" */ '@/views/groupteam/children/Groupteamdetail');
const Groupteamlaxin = () => import(/* webpackChunkName: "groupteamlaxin" */ '@/views/groupteam/children/Groupteamlaxin');
const Groupteamfenxiao = () => import(/* webpackChunkName: "groupteamfenxiao" */ '@/views/groupteam/children/Groupteamfenxiao');
const Customerlist = () => import(/* webpackChunkName: "customerlist" */ '@/views/customerlist/Customerlist');
const Customerreport = () => import(/* webpackChunkName: "customerreport" */ '@/views/customerreport/Customerreport');
const Permission = () => import(/* webpackChunkName: "permission" */ '@/views/permission/Permission');
const Getmoney = () => import(/* webpackChunkName: "getmoney" */ '@/views/getmoney/Getmoney');
const Groupbuystat = () => import(/* webpackChunkName: "groupbuystat" */ '@/views/groupbuystat/Groupbuystat');
const Gongstat = () => import(/* webpackChunkName: "gongstat" */ '@/views/gongstat/Gongstat');
const Service = () => import(/* webpackChunkName: "service" */ '@/views/service/Service');
const Detail = () => import(/* webpackChunkName: "detail" */ '@/views/detail/Detail');


const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)

}
Vue.use(Router)

const router = new Router({
  // mode: 'history',
  // base:'/dist',
  routes: [
    {
      path: '/',
      redirect: '/statistical'
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '',
      component: Homepage,
      children: [
        {
          path: '/statistical',
          component: Statistical //统计
        },
        {
          path: '/groupbuystat',
          component: Groupbuystat //小龙直营统计
        },
        {
          path: '/gongstat',
          component: Gongstat //团长统计
        },
        {
          path: '/management',
          component: Management //商品管理
        },
        {
          path: '/management/addmanagement',
          meta: {
            path: "/management"
          },
          component: Addmanagement, //商品管理+添加商品
          // name:Addmanagement
        },
        {
          path: '/service',
          component: Service //客服管理
        },
        {
          path: '/detail',
          component: Detail//详情
        },
        {
          path: '/settlement',
          component: Settlement//提现审核 点击->结算详情
        },
        {
          path: '/supplier',
          component: Supplier
        },
        {
          path: '/groupteam',
          component: Groupteam //团长->团长管理
        },
        {
          path: '/groupteamdetail',
          component: Groupteamdetail, //团长->团长管理 ->详情
        },
        {
          path: '/groupteamlaxin',
          component: Groupteamlaxin //团长->团长管理 ->拉新团长人数
        },
        {
          path: '/groupteamfenxiao',
          component: Groupteamfenxiao //团长->团长管理 ->分销人数
        },
        {
          path: '/business',
          component: Business //团长 => 提现审核
        },
        {
          path: '/gongment',
          component: Gongment
        },
        {
          path: '/gongmoney',
          component: Gongmoney
        },
        {
          path: '/activity',
          component: Activity
        },
        {
          path: '/directly',
          component: Directly
        },
        // {
        //   path: '/directly/addevent',
        //   meta: {
        //     path: "/directly"
        //   },
        //   component: Addevent //供应商 供-详情页面
        // },
        {
          path: '/directly/addeventpage',
          meta: {
            path: "/directly"
          },
          component: Addeventpage //供应商 供-详情页面
        },
        {
          path: '/directly/editEventPage',
          meta: {
            path: "/directly"
          },
          component: EditEventPage //供应商 供-详情页面
        },
        {
          path: '/tuanorder',
          component: Tuanorder, //团长订单

        },
        {
          path: '/torderdetail',
          component: Torderdetail //团长订单 =>详情
        },
        {
          path: '/gongorder',
          component: Gongorder //供应商订单
        },
        {
          path: '/tuanbao',
          component: Tuanbao //团长报表
        },
        {
          path: '/gongbao',
          component: Gongbao //供应商报表
        },
        {
          path: '/post',
          component: Post //营销海报
        },
        {
          path: '/gongdepage',
          component: Gongdepage //供应商 详情页面
        },
        {
          path: '/torderdetail',
          component: Torderdetail //供应商 团-详情页面
        },
        {
          path: '/gorderdetail',
          component: Gorderdetail //供应商 供-详情页面
        },
        // {
        //   path: '/addevent',
        //   component: Addevent //供应商 供-详情页面
        // },
        {
          path: '/customerlist',
          component: Customerlist, //供应商后台  概况,

        },
        {
          path: '/customerreport',  //管理员
          component: Customerreport

        },
        {
          path: '/permission',  //管理员
          component: Permission

        },
        {
          path: '/getmoney',  //管理员
          component: Getmoney

        },
        // {
        //   path: '*',
        //   component: NotFoundComponent
        // }
      ]
    }
  ]
})


router.beforeEach((to, from, next) => {
  if (!localStorage.getItem('token') && to.path !== '/login') {
    next('/login')
  } else if (localStorage.getItem('token') && to.path === '/login') {
    next(from)
  } else {
    next()
  }

})


export default router
